using System.Collections.Generic;
using System.IO;
using System.Linq;
using WebServer.BusinessLogic.Web.Cache;

namespace WebServer.BusinessLogic.Handlers.Interface
{
    public class FileSystemProvider : IFileSystemProvider
    {
        public bool DirectoryExists(string path)
        {
            return Directory.Exists(path);
        }

        public DirectoryInfo CreateDirectoryInfo(string path)
        {
            return new DirectoryInfo(path);
        }

        public IList<FileSystemInfoModel> GetFileSystemInfos(string path)
        {
            var di = CreateDirectoryInfo(path);
            var fsi = di.GetFileSystemInfos();

            var myFsiList = fsi.Select(fs => new FileSystemInfoModel(fs.Name, fs.Extension, fs.FullName)).ToList();

            return myFsiList;
        }

        public bool FileExists(string path)
        {
            return File.Exists(path);
        }

        public byte[] GetDataOrFile(string cacheKey, string filePath)
        {
            return CacheManager.GetCacheOrFile(cacheKey, filePath);
        }
    }

    public class FileSystemInfoModel
    {
        public FileSystemInfoModel(string name, string extension, string fullName)
        {
            Name = name;
            Extension = extension;
            this.FullName = fullName;
        }

        public FileSystemInfoModel()
        {
        }

        public string Name { get; set; }

        public string Extension { get; set; }

        public string FullName { get; set; }
    }
}